package org.hank.compose_yyzs.viewmodel

import androidx.compose.runtime.MutableState
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.cachedIn
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import org.hank.compose_yyzs.bean.MeasureTaskListBean
import org.hank.compose_yyzs.bean.PageWrapper
import org.hank.compose_yyzs.http.ApiService
import org.hank.compose_yyzs.http.bean.HttpWrapBean
import org.hank.compose_yyzs.ui.paging.simplePager
import javax.inject.Inject

//  ┏┓　　　┏┓
//┏┛┻━━━┛┻┓
//┃　　　　　　　┃
//┃　　　━　　　┃
//┃　┳┛　┗┳　┃
//┃　　　　　　　┃
//┃　　　┻　　　┃
//┃　　　　　　　┃
//┗━┓　　　┏━┛
//    ┃　　　┃                  神兽保佑
//    ┃　　　┃                  永无BUG！
//    ┃　　　┗━━━┓
//    ┃　　　　　　　┣┓
//    ┃　　　　　　　┏┛
//    ┗┓┓┏━┳┓┏┛
//      ┃┫┫　┃┫┫
//      ┗┻┛　┗┻┛
/**
 *@auth: Hank
 *邮箱: cs16xiaoc1@163.com
 *创建时间: 2023/9/25 14:18
 *描述:
 */
@HiltViewModel
class MeasureResultViewModel @Inject constructor(var apiService: ApiService) : ViewModel() {
    var isRefresh : MutableStateFlow<Boolean> = MutableStateFlow(false)
    val pager =
        simplePager(isRefresh) {
            delay(100)
            HttpWrapBean(
                "200", "success", PageWrapper(
                    currPage = it,
                    pageSize = 5,
                    totalCount = 10,
                    datas = getCurrentList(it.toString()),
                    totalPage = 2
                )
            )
        }.cachedIn(viewModelScope)


    fun refresh() {

    }

    private fun getCurrentList(currentPage: String): List<MeasureTaskListBean> {
        var tempDataList = mutableListOf(
            MeasureTaskListBean(
                blockName = "测试楼栋1",
                createdDate = "2023年9月21日15:32:44",
                floorName = "3楼",
                projectName = "${currentPage}测试项目1${System.currentTimeMillis()}",
                stageName = "1",
                roomName = "301",
                stageType = 1,
                stationNo = "1",
                stationTaskNo = "123",
                taskType = 0,
                unitName = "1单元",
                roomId = 11,
                status = 0
            ),
            MeasureTaskListBean(
                blockName = "测试楼栋1",
                createdDate = "2023年9月21日15:32:44",
                floorName = "3楼",
                projectName = "${currentPage}测试项目2${System.currentTimeMillis() + 1}",
                stageName = "1",
                roomName = "301",
                stageType = 1,
                stationNo = "1",
                stationTaskNo = "123",
                taskType = 0,
                unitName = "1单元",
                roomId = 11,
                status = 0
            ),
            MeasureTaskListBean(
                blockName = "测试楼栋1",
                createdDate = "2023年9月21日15:32:44",
                floorName = "3楼",
                projectName = "${currentPage}测试项目3${System.currentTimeMillis() + 2}",
                stageName = "1",
                roomName = "301",
                stageType = 1,
                stationNo = "1",
                stationTaskNo = "123",
                taskType = 0,
                unitName = "1单元",
                roomId = 11,
                status = 0
            ),
            MeasureTaskListBean(
                blockName = "测试楼栋1",
                createdDate = "2023年9月21日15:32:44",
                floorName = "3楼",
                projectName = "${currentPage}测试项目4${System.currentTimeMillis() + 3}",
                stageName = "1",
                roomName = "301",
                stageType = 1,
                stationNo = "1",
                stationTaskNo = "123",
                taskType = 0,
                unitName = "1单元",
                roomId = 11,
                status = 0
            ),
            MeasureTaskListBean(
                blockName = "测试楼栋1",
                createdDate = "2023年9月21日15:32:44",
                floorName = "3楼",
                projectName = "${currentPage}测试项目5${System.currentTimeMillis() + 4}",
                stageName = "1",
                roomName = "301",
                stageType = 1,
                stationNo = "1",
                stationTaskNo = "123",
                taskType = 0,
                unitName = "1单元",
                roomId = 11,
                status = 0
            )
        )
        return tempDataList
    }
}